package com.woniu.controller;

import com.woniu.entity.RbacPerm;
import com.woniu.entity.ResponseEntity;
import com.woniu.service.RbacPermService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author WenXin
 * @version 1.0
 * @description: TODO
 * @date 2022/9/3 12:50
 */
@RestController
@RequestMapping("/rbacPerm")
@CrossOrigin
public class RbacPermController {
    @Autowired
    RbacPermService rbacPermService;

    //初始分页的方法
    @GetMapping("/{pageNum}/{pageSize}")
    public ResponseEntity findAll(@PathVariable("pageNum") int pageNum, @PathVariable("pageSize") int pageSize) {
        return rbacPermService.findAll(pageNum, pageSize);
    }

    //增
    @PostMapping("/")
    public ResponseEntity addOne(@RequestBody RbacPerm rbacPerm) {
        int i = rbacPermService.addOne(rbacPerm);
        if (i > 0) {
            return new ResponseEntity(200, "添加成功", null);
        }
        return new ResponseEntity(500, "添加失败", null);
    }

    //删
    @DeleteMapping("/{id}")
    public ResponseEntity deleteById(@PathVariable int id) {
        int i = rbacPermService.deleteById(id);
        if (i > 0) {
            return new ResponseEntity(200, "删除成功", null);
        }
        return new ResponseEntity(500, "删除失败", null);
    }

    //改
    @PutMapping("/")
    public ResponseEntity update(@RequestBody RbacPerm rbacPerm) {
        int i = rbacPermService.update(rbacPerm);
        if (i > 0) {
            return new ResponseEntity(200, "更新成功", null);
        }
        return new ResponseEntity(500, "更新失败", null);
    }

    //模糊搜索
    @PutMapping("/{pageNum}/{pageSize}")
    public ResponseEntity searchByPerm(@RequestBody RbacPerm rbacPerm, @PathVariable("pageNum") int pageNum, @PathVariable("pageSize") int pageSize) {

        return rbacPermService.searchByPerms(rbacPerm, pageNum, pageSize);
    }


}
